home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1993 July / InfoMagic USENET CD-ROM July 1993.ISO / sources / unix / volume15 / gbench / part01 next >
Encoding:
Internet Message Format  |  1988-06-12  |  47.7 KB

  1. Subject:  v15i068:  Graphics benchmark toolkit for X, Part01/02
  2. Newsgroups: comp.sources.unix
  3. Sender: sources
  4. Approved: rsalz@uunet.UU.NET
  5.  
  6. Submitted-by: Craig Dunwoody <dunwoody@lurch.stanford.edu>
  7. Posting-number: Volume 15, Issue 68
  8. Archive-name: gbench/part01
  9.  
  10. Gbench is a graphics benchmark tool.  It currently supports 2D
  11. immediate-mode graphics and runs on top of the X Window System (both
  12. Version 10 and Version 11) and Unix.  It is written in C and it directly
  13. calls the low-level window system client library; no toolkit is used.  It
  14. is being developed by Craig Dunwoody and Mark Linton at Stanford
  15. University's Computer Systems Lab under the Quantum project, through a
  16. gift from Digital Equipment Corporation.  It may be freely distributed
  17. under the conditions listed in the accompanying copyright notice.
  18.  
  19. Gbench is not a graphics benchmark.  Rather, it is a tool that lets you
  20. construct and run your own benchmarks.  When gbench starts up, it creates
  21. an X window and reads commands from standard input, one per line.  Each
  22. command directs gbench to repeatedly perform a particular drawing
  23. operation.  Gbench copies the command line to standard output, executes
  24. the command, and prints on standard output the host load average, the time
  25. for each iteration, and the number of iterations per second.  All times
  26. are measured in real (wall-clock) time.
  27.  
  28.  
  29. Thanks a lot,
  30. Craig Dunwoody
  31. Internet:   dunwoody@lurch.stanford.edu
  32. USEnet:     {ucbvax,decvax}!decwrl!lurch.stanford.edu!dunwoody
  33. Phone:      (415) 725-3733
  34.  
  35. --------------------------
  36. #! /bin/sh
  37. # This is a shell archive.  Remove anything before this line, then unpack
  38. # it by saving it into a file and typing "sh file".  To overwrite existing
  39. # files, type "sh file -c".  You can also feed this as standard input via
  40. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  41. # will see the following message at the end:
  42. #        "End of archive 1 (of 2)."
  43. # Contents:  COPYRIGHT Makefile-dist README cmds.c exec.c gbench.h
  44. #   main.c utils.c
  45. # Wrapped by rsalz@fig.bbn.com on Mon Jun 13 15:32:46 1988
  46. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  47. if test -f 'COPYRIGHT' -a "${1}" != "-c" ; then 
  48.   echo shar: Will not clobber existing file \"'COPYRIGHT'\"
  49. else
  50. echo shar: Extracting \"'COPYRIGHT'\" \(702 characters\)
  51. sed "s/^X//" >'COPYRIGHT' <<'END_OF_FILE'
  52. XCopyright (c) 1988 by The Board of Trustees
  53. Xof the Leland Stanford Junior University.
  54. X
  55. XPermission to use, copy, modify, and distribute this
  56. Xsoftware and its documentation for any purpose and without
  57. Xfee is hereby granted, provided that the above copyright
  58. Xnotice appear in all copies and that both that copyright
  59. Xnotice and this permission notice appear in supporting
  60. Xdocumentation, and that the name of Stanford not be used in
  61. Xadvertising or publicity pertaining to distribution of the
  62. Xsoftware without specific, written prior permission.
  63. X
  64. XStanford makes no representations about the suitability of
  65. Xthis software for any purpose.  The Software is provided "as is"
  66. Xwithout express or implied warranty.
  67. END_OF_FILE
  68. if test 702 -ne `wc -c <'COPYRIGHT'`; then
  69.     echo shar: \"'COPYRIGHT'\" unpacked with wrong size!
  70. fi
  71. # end of 'COPYRIGHT'
  72. fi
  73. if test -f 'Makefile-dist' -a "${1}" != "-c" ; then 
  74.   echo shar: Will not clobber existing file \"'Makefile-dist'\"
  75. else
  76. echo shar: Extracting \"'Makefile-dist'\" \(407 characters\)
  77. sed "s/^X//" >'Makefile-dist' <<'END_OF_FILE'
  78. X.SILENT:
  79. X
  80. XMACHINE = VAX
  81. XXVERSION= X11
  82. X
  83. X# for gprof profiling, put -DGPROF in CFLAGS and -pg in LDFLAGS
  84. X
  85. XCC    = cc
  86. XCFLAGS     = -O -I. -D${MACHINE} -D${XVERSION}
  87. XLD    = cc
  88. XLDFLAGS    =
  89. XLIBS    = -l${XVERSION} -lm
  90. XOBJS    = cmds.o exec.o main.o ops.o utils.o
  91. XPROG    = gbench
  92. X
  93. X.c.o:
  94. X    echo compiling $*.c
  95. X    ${CC} ${CFLAGS} -c $*.c
  96. X
  97. X${PROG}: ${OBJS}
  98. X    echo linking ${PROG}
  99. X    ${LD} ${LDFLAGS} -o $@ ${OBJS} ${LIBS}
  100. X
  101. X${OBJS}: gbench.h
  102. END_OF_FILE
  103. if test 407 -ne `wc -c <'Makefile-dist'`; then
  104.     echo shar: \"'Makefile-dist'\" unpacked with wrong size!
  105. fi
  106. # end of 'Makefile-dist'
  107. fi
  108. if test -f 'README' -a "${1}" != "-c" ; then 
  109.   echo shar: Will not clobber existing file \"'README'\"
  110. else
  111. echo shar: Extracting \"'README'\" \(4386 characters\)
  112. sed "s/^X//" >'README' <<'END_OF_FILE'
  113. Xgbench Version 1.0
  114. X
  115. XGbench is a graphics benchmark tool.  It currently supports 2D immediate-mode
  116. Xgraphics and runs on top of the X Window System (both Version 10 and Version
  117. X11) and Unix.  It is written in C and it directly calls the low-level window
  118. Xsystem client library; no toolkit is used.  It is being developed by Craig
  119. XDunwoody and Mark Linton at Stanford University's Computer Systems Lab under
  120. Xthe Quantum project, through a gift from Digital Equipment Corporation.  It may
  121. Xbe freely distributed under the conditions listed in the accompanying copyright
  122. Xnotice.
  123. X
  124. XGbench is not a graphics benchmark.  Rather, it is a tool that lets you
  125. Xconstruct and run your own benchmarks.  When gbench starts up, it creates an X
  126. Xwindow and reads commands from standard input, one per line.  Each command
  127. Xdirects gbench to repeatedly perform a particular drawing operation.  Gbench
  128. Xcopies the command line to standard output, executes the command, and prints on
  129. Xstandard output the host load average, the time for each iteration, and the
  130. Xnumber of iterations per second.  All times are measured in real (wall-clock)
  131. Xtime.
  132. X
  133. XYou can use gbench either interactively, by typing commands and viewing
  134. Xthe results immediately, or in batch mode, with standard input redirected
  135. Xto a script file and output redirected to a log file.  If you don't want to
  136. Xcreate your own script file, there is a built-in default script.
  137. X
  138. XGbench is primarily intended as a benchmarking tool.  You may also find it
  139. Xuseful as a graphics system exerciser.  If you are developing an application
  140. Xprogram, and some graphics operation isn't behaving properly, you may be able
  141. Xto use gbench to find out if the underlying graphics system implementation is
  142. Xdoing the right thing.  Gbench is NOT, however, intended as a graphics system
  143. Xverification tool.  It allows you to exercise most of the drawing functions
  144. Xsupported by the graphics server, but for any given function, the only
  145. Xparameters that gbench lets you vary are those (such as size) that we
  146. Xconsider to be likely to affect performance.
  147. X
  148. XIn the future, we hope to extend gbench and provide tools for combining and
  149. Xformatting raw log files.  Proposed extensions include 3D graphics and
  150. Xintegration with a more comprehensive set of workstation benchmarks.  If there
  151. Xis interest, we are willing to act as a clearinghouse for benchmark scripts and
  152. Xresults.
  153. X
  154. XVersion 1.0 of gbench represents our first attempt to address the problem of
  155. Xcharacterizing graphics performance in a distributed environment.  There are
  156. Xmany complex issues in this area that remain unresolved, and we expect that we
  157. Xwill be able to substantially improve gbench as we learn more.  By making
  158. Xgbench widely available, we hope to hasten the process of making it as
  159. Xportable, bug-free, complete, and fair as possible.
  160. X
  161. XSpeaking of bugs, there is apparently a bug in the beta release of the
  162. Xawm window manager for X11R2 that causes the "map" command to hang
  163. X\fIgbench\fP.  For this reason, we have removed "map" from the default
  164. Xscript.  We have not found this problem under any of the other X11R2
  165. Xwindow managers, including the standard uwm.
  166. X
  167. XWe would be most pleased to receive any comments, bugfixes, scripts, or results
  168. Xthat you might have.  Our address is:
  169. X
  170. XInternet:  gbench@lurch.stanford.edu
  171. XUSEnet:    {ucbvax,decvax}!decwrl!lurch.stanford.edu!gbench
  172. X
  173. XGbench source code is available in compressed and uncompressed shar and tar
  174. Xformats through anonymous FTP to lurch.stanford.edu (36.22.0.14).
  175. X
  176. XTo build gbench:
  177. X
  178. X1.  Copy Makefile-dist to Makefile.
  179. X
  180. X2.  In Makefile, set MACHINE to your machine type.  Gbench has been tested
  181. X    with X10 and X11 on machine types VAX, SUN3, and SUN4.  The code should
  182. X    be quite portable.  The difference between the VAX and SUN versions
  183. X    is in the definition of GetLoad() in utils.c.  When there is a more
  184. X    reasonable way to get the load (suggestions are welcome), this problem
  185. X    will go away.
  186. X
  187. X3.  In Makefile, set XVERSION to X10 or X11 as appropriate.
  188. X
  189. X4.  In Makefile, add the indicated flags to CFLAGS and LDFLAGS if you want
  190. X    to do gprof profiling.
  191. X
  192. X5.  If your X header files are not in /usr/include/${XVERSION},
  193. X    create the  symbolic link "X10" or "X11", pointing to the appropriate
  194. X    X header file directory, in the main gbench directory.
  195. X
  196. X6.  Make sure that lib${XVERSION}.a exists in your standard library
  197. X    directory.
  198. X
  199. X7.  "make"
  200. END_OF_FILE
  201. if test 4386 -ne `wc -c <'README'`; then
  202.     echo shar: \"'README'\" unpacked with wrong size!
  203. fi
  204. # end of 'README'
  205. fi
  206. if test -f 'cmds.c' -a "${1}" != "-c" ; then 
  207.   echo shar: Will not clobber existing file \"'cmds.c'\"
  208. else
  209. echo shar: Extracting \"'cmds.c'\" \(7415 characters\)
  210. sed "s/^X//" >'cmds.c' <<'END_OF_FILE'
  211. X#include <gbench.h>
  212. X
  213. XResult ParseOpts(os,sfp,ofp)
  214. X    char*    os;
  215. X    OptFlags*    sfp;
  216. X    OptFlags*    ofp;
  217. X{
  218. X    int        i;
  219. X    char    ps[MaxStr];
  220. X    bool*    ofa = (bool*)ofp;
  221. X    char*    osp = os;
  222. X    Result    result = Succeeded;
  223. X    bool*    sfa = (bool*)sfp;
  224. X    char*    t;
  225. X    TokenState    ts;
  226. X
  227. X    for (i=0;i<(sizeof(OptFlags)/sizeof(bool));i++) ofa[i] = false;
  228. X    strcpy(ps,osp);
  229. X    *osp = '\0';
  230. X    if (t=StrToken(ps,",",&ts)) do {
  231. X    i = -1;
  232. X    if (!strcmp(t,"ac")) i = &ofp->altcolor-ofa;
  233. X    else if (!strcmp(t,"af")) i = &ofp->altfont-ofa;
  234. X    else if (!strcmp(t,"ag")) i = &ofp->altgc-ofa;
  235. X    else if (!strcmp(t,"aw")) i = &ofp->altwin-ofa;
  236. X    else if (!strcmp(t,"d")) i = &ofp->drag-ofa;
  237. X    else if (!strcmp(t,"f")) i = &ofp->fill-ofa;
  238. X    else if (!strcmp(t,"i")) i = &ofp->invert-ofa;
  239. X    else if (!strcmp(t,"m")) i = &ofp->profile-ofa;
  240. X    else if (!strcmp(t,"o")) i = &ofp->overlap-ofa;
  241. X    else if (!strcmp(t,"os")) i = &ofp->offsrc-ofa;
  242. X    else if (!strcmp(t,"od")) i = &ofp->offdest-ofa;
  243. X    else if (!strcmp(t,"p")) i = &ofp->poll-ofa;
  244. X    else if (!strcmp(t,"ps")) i = &ofp->polyself-ofa;
  245. X    else if (!strcmp(t,"pw")) i = &ofp->polywind-ofa;
  246. X    else if (!strcmp(t,"r")) i = &ofp->setdefaults-ofa;
  247. X    else if (!strcmp(t,"s")) i = &ofp->stipple-ofa;
  248. X    else if (!strcmp(t,"t")) i = &ofp->tile-ofa;
  249. X    else if (!strcmp(t,"u")) i = &ofp->unbatched-ofa;
  250. X    if ((i>=0)&&!ofa[i]) {
  251. X        if (!sfa[i]) result = OptNotSupported;
  252. X        ofa[i] = true;
  253. X        sprintf(osp,"%s,",t);
  254. X        osp += strlen(osp);
  255. X    }
  256. X    } while (t=StrToken(nil,",",&ts));
  257. X    if (osp>os) *--osp = '\0';
  258. X    return result;
  259. X}
  260. X
  261. Xchar* GetToken(sp,first)
  262. X    State*  sp;
  263. X    bool    first;
  264. X{
  265. X    if (!sp->strinput) {
  266. X    if (first) {
  267. X        while((sp->argindex<sp->argc)&&(*sp->argv[sp->argindex]!='-')) {
  268. X        sp->argindex++;
  269. X        }
  270. X        if (sp->argindex>=sp->argc) return nil;
  271. X        else return sp->argv[sp->argindex++];
  272. X    }
  273. X    else {
  274. X        if (*sp->argv[sp->argindex]=='-') return nil;
  275. X        else return sp->argv[sp->argindex++];
  276. X    }
  277. X    }
  278. X    else return StrToken(first?sp->instr:nil," ",&sp->ts);
  279. X}
  280. X
  281. Xint ScanInt(s,min,max)
  282. X    char*   s;
  283. X    int        min;
  284. X    int        max;
  285. X{
  286. X    int i;
  287. X
  288. X    sscanf(s,"%d",&i);
  289. X    return i = Limit(i,min,max);
  290. X}
  291. X
  292. Xvoid SetParam(sp,pp,n,v,concat)
  293. X    State*  sp;
  294. X    Params* pp;
  295. X    char*   n;
  296. X    char*   v;
  297. X    bool    concat;
  298. X{
  299. X    if (!strcmp(n,"angle")) pp->angle = ScanInt(v,0,360);
  300. X    else if (!strcmp(n,"aspect")) {
  301. X    sscanf(v,"%f",&pp->aspect);
  302. X    if (pp->aspect<MinAspect) pp->aspect = MinAspect;
  303. X    }
  304. X    else if (!strcmp(n,"count")) pp->count = ScanInt(v,0,MaxNum);
  305. X    else if (!strcmp(n,"fonts")) strcpy(pp->fonts,v);
  306. X    else if (!strcmp(n,"lwidth")) pp->lwidth = ScanInt(v,0,_DisplayWidth);
  307. X    else if (!strcmp(n,"maxshift")) pp->maxshift = ScanInt(v,0,_DisplayWidth);
  308. X    else if (!strcmp(n,"nchar")) pp->nchar = ScanInt(v,0,MaxStr);
  309. X    else if (!strcmp(n,"nvert")) pp->nvert = ScanInt(v,3,MaxVert);
  310. X    else if (!strcmp(n,"nwin")) pp->nwin = ScanInt(v,0,MaxNum);
  311. X    else if (!strcmp(n,"offset")) sscanf(v,"%f",&pp->offset);
  312. X    else if (!strcmp(n,"opts")) {
  313. X    if (concat) {
  314. X        if (strlen(pp->opts)&&strlen(v)) strcat(pp->opts,",");
  315. X        strcat(pp->opts,v);
  316. X    }
  317. X    else strcpy(pp->opts,v);
  318. X    }
  319. X    else if (!strcmp(n,"outfile")) strcpy(pp->outfile,v);
  320. X    else if (!strcmp(n,"ptsize")) pp->ptsize = ScanInt(v,0,_DisplayHeight);
  321. X    else if (!strcmp(n,"size")) pp->size = ScanInt(v,0,_DisplayWidth);
  322. X    else if (!strcmp(n,"tag")) strcpy(pp->tag,v);
  323. X    else if (!strcmp(n,"timegoal")) pp->timegoal = ScanInt(v,0,MaxNum);
  324. X    else if (!strcmp(n,"winsize")) pp->winsize = ScanInt(v,1,_DisplayHeight);
  325. X}
  326. X
  327. Xvoid ParseParams(sp,cp,pp,print)
  328. X    State*    sp;
  329. X    Cmd*    cp;
  330. X    Params*    pp;
  331. X    bool    print;
  332. X{
  333. X    int        i;
  334. X    char*   t = nil;
  335. X    char*   v;
  336. X
  337. X    if (cp->index!=NilIndex) {
  338. X    for (
  339. X        i=0;
  340. X        (i<MaxPositional)&&OpNames[(int)cp->index][1+i]&&
  341. X        (t=GetToken(sp,false))&&!strchr(t,'=');
  342. X        i++
  343. X    ) {
  344. X        SetParam(sp,pp,OpNames[(int)cp->index][1+i],t,true);
  345. X    }
  346. X    }
  347. X    do if (t&&(v=strchr(t,'='))) {
  348. X    *v++ = '\0';
  349. X    SetParam(sp,pp,t,v,false);
  350. X    if (print) PrintParam(Out(sp,cp),pp,"  ",t,"");
  351. X    *--v = '=';
  352. X    } while (t=GetToken(sp,false));
  353. X    if (print) {
  354. X    putc('\n',Out(sp,cp));
  355. X    fflush(Out(sp,cp));
  356. X    }
  357. X    if (strcmp(sp->fonts,pp->fonts)) SetFonts(sp,pp);
  358. X    if (strcmp(sp->outfile,pp->outfile)) SetOutfile(sp,pp);
  359. X    if (sp->winsize!=pp->winsize) SetWinsize(sp,pp);
  360. X    if (ParseOpts(pp->opts,&sp->supopts,&cp->o)!=Succeeded) {
  361. X    cp->result = OptNotSupported;
  362. X    }
  363. X}
  364. X
  365. Xvoid ParseCmd(sp,cp)
  366. X    State*  sp;
  367. X    Cmd*    cp;
  368. X{
  369. X    cp->result = sp->supcmds[(int)cp->index]?Succeeded:CmdNotSupported;
  370. X    ParseParams(sp,cp,&cp->p,false);
  371. X    cp->func = cp->o.invert?GXinvert:GXcopy;
  372. X    sp->previndex = cp->index;
  373. X    CopyParams(&sp->prevparams,&cp->p);
  374. X    if (cp->o.setdefaults) CopyParams(&sp->defaults,&cp->p);
  375. X}
  376. X
  377. Xvoid PushInput(sp,fn)
  378. X    State*  sp;
  379. X    char*   fn;
  380. X{
  381. X    if ((sp->indepth<MaxIndepth)&&!(sp->infds[++sp->indepth]=fopen(fn,"r"))) {
  382. X    sp->indepth--;
  383. X    }
  384. X}
  385. X
  386. Xbool PopInput(sp)
  387. X    State*  sp;
  388. X{
  389. X    bool nonempty = (bool)(sp->indepth>0);
  390. X
  391. X    if (nonempty) sp->indepth--;
  392. X    return nonempty;
  393. X}
  394. X
  395. Xvoid PrintComment(sp,cp,t)
  396. X    State*  sp; 
  397. X    Cmd*    cp;
  398. X    char*   t;
  399. X{
  400. X    char* te;
  401. X
  402. X    if (sp->strinput) {
  403. X    te = t+strlen(t);
  404. X     if (te<sp->ts.end) *te = ' ';
  405. X    fprintf(Out(sp,cp),"%s\n",t);
  406. X    }
  407. X    else {
  408. X    do fprintf(Out(sp,cp),"%s ",t); while (t=GetToken(sp,false));
  409. X    putc('\n',Out(sp,cp));
  410. X    }
  411. X}
  412. X
  413. Xbool GetLine(sp)
  414. X    State*  sp;
  415. X{
  416. X    char* cp;
  417. X
  418. X    if (sp->scriptindex>=0) {
  419. X    strcpy(sp->instr,Script[sp->scriptindex]);
  420. X    if (!Script[++sp->scriptindex]) sp->scriptindex = -1;
  421. X    sp->strinput = true;
  422. X    }
  423. X    else if (sp->argindex>=sp->argc) {
  424. X    while (!fgets(sp->instr,MaxStr,sp->infds[sp->indepth])) {
  425. X        if (!PopInput(sp)) return false;
  426. X    }
  427. X    if (cp=strchr(sp->instr,'\n')) *cp='\0';
  428. X    sp->strinput = true;
  429. X    }
  430. X    else sp->strinput = false;
  431. X    return true;
  432. X}
  433. X
  434. Xbool GetCmd(sp,cp)
  435. X    State*  sp;
  436. X    Cmd*    cp;
  437. X{
  438. X    char*   t;
  439. X    int     tlen;
  440. X
  441. X    while (true) {
  442. X    cp->index = NilIndex;
  443. X    if (!GetLine(sp)) return false;
  444. X    if (t=GetToken(sp,true)) {
  445. X        if (*t=='-') t++;
  446. X        if (*t=='@') {
  447. X        t++;
  448. X        cp->o.silent = true;
  449. X        }
  450. X        else cp->o.silent = false;
  451. X        tlen = strlen(t);
  452. X        if (!strncmp(t,"config",tlen)) {
  453. X        fprintf(Out(sp,cp),"config\n");
  454. X        PrintConfig(Out(sp,cp),sp);
  455. X        putc('\n',Out(sp,cp));
  456. X        }
  457. X        else if (!strncmp(t,"defaults",tlen)) {
  458. X        fprintf(Out(sp,cp),"defaults");
  459. X        ParseParams(sp,cp,&sp->defaults,true);
  460. X        PrintParams(stderr,sp,&sp->defaults);
  461. X        putc('\n',stderr);
  462. X        }
  463. X        else if (!strncmp(t,"help",tlen)) {
  464. X        PrintHelp(Out(sp,cp));
  465. X        putc('\n',stderr);
  466. X        }
  467. X        else if (!strncmp(t,"init",tlen)) {
  468. X        fprintf(Out(sp,cp),"init\n");
  469. X        InitParams(sp,&sp->defaults);
  470. X        PrintParams(stderr,sp,&sp->defaults);
  471. X        putc('\n',stderr);
  472. X        }
  473. X        else if (!strncmp(t,"quit",tlen)) {
  474. X        return false;
  475. X        }
  476. X        else if (!strncmp(t,"script",tlen)) {
  477. X        fprintf(Out(sp,cp),"script");
  478. X        if (t=GetToken(sp,false)) fprintf(Out(sp,cp)," %s",t);
  479. X        putc('\n',Out(sp,cp));
  480. X        if (t) PushInput(sp,t);
  481. X        else sp->scriptindex = 0;
  482. X        }
  483. X        else if (*t=='#') {
  484. X        PrintComment(sp,cp,t);
  485. X        }
  486. X        else if ((*t=='!')&&((cp->index=sp->previndex)!=NilIndex)) {
  487. X        CopyParams(&cp->p,&sp->prevparams);
  488. X        ParseCmd(sp,cp);
  489. X        return true;
  490. X        }
  491. X        else if ((cp->index=GetOpIndex(t))!=NilIndex) {
  492. X        CopyParams(&cp->p,&sp->defaults);
  493. X        ParseCmd(sp,cp);
  494. X        return true;
  495. X        }
  496. X    }
  497. X    else putchar('\n');
  498. X    }
  499. X}
  500. END_OF_FILE
  501. if test 7415 -ne `wc -c <'cmds.c'`; then
  502.     echo shar: \"'cmds.c'\" unpacked with wrong size!
  503. fi
  504. # end of 'cmds.c'
  505. fi
  506. if test -f 'exec.c' -a "${1}" != "-c" ; then 
  507.   echo shar: Will not clobber existing file \"'exec.c'\"
  508. else
  509. echo shar: Extracting \"'exec.c'\" \(6770 characters\)
  510. sed "s/^X//" >'exec.c' <<'END_OF_FILE'
  511. X#include <gbench.h>
  512. X
  513. Xvoid Start(sp,cp)
  514. X    State*  sp;
  515. X    Cmd*    cp;
  516. X{
  517. X    int i;
  518. X    int    style;
  519. X
  520. X    cp->colorfg = _WhitePixel;
  521. X    cp->colorbg = _BlackPixel;
  522. X    if (cp->p.maxshift>0) cp->dx = cp->dy = 1;
  523. X    else cp->dx = cp->dy = 0;
  524. X    cp->gc = sp->gc1;
  525. X    cp->shift = 0;
  526. X    cp->w = sp->w1;
  527. X    sp->dest1 = sp->w1;
  528. X    sp->src1 = sp->w1;
  529. X#   ifdef X11
  530. X    if (cp->o.offdest||cp->o.offsrc) {
  531. X        if (!sp->offpix) {
  532. X        cp->o.offdest = cp->o.offsrc = false;
  533. X        cp->result = NoOffscreenMem;
  534. X        }
  535. X        else {
  536. X        if (cp->o.offdest) sp->dest1 = sp->offpix;
  537. X        if (cp->o.offsrc) sp->src1 = sp->offpix;
  538. X        XFillRectangle(
  539. X            sp->d,sp->offpix,DefaultGC(sp->d,DefaultScreen(sp->d)),0,0,
  540. X            sp->winsize,sp->winsize
  541. X        );
  542. X        }
  543. X    }
  544. X#   endif X11
  545. X    cp->dest = sp->dest1;
  546. X    cp->src = sp->src1;
  547. X    fprintf(Out(sp,cp),"%s",OpNames[(int)cp->index][0]);
  548. X    for (i=0;(i<MaxPositional)&&OpNames[(int)cp->index][1+i];i++) {
  549. X    PrintParam(Out(sp,cp),&cp->p,"  ",OpNames[(int)cp->index][1+i],"");
  550. X    }
  551. X    PrintParam(Out(sp,cp),&cp->p,"  ","count","\n");
  552. X    fflush(Out(sp,cp));
  553. X    if (cp->o.altwin&&!sp->altwin) {
  554. X    MapWin(sp,sp->w2);
  555. X    sp->altwin = true;
  556. X    }
  557. X    else if (sp->altwin&&!cp->o.altwin) {
  558. X    UnmapWin(sp,sp->w2);
  559. X    sp->altwin = false;
  560. X    }
  561. X    if (cp->o.overlap) {
  562. X    XMapWindow(DARGC sp->cw1);
  563. X    if (cp->o.altwin) XMapWindow(DARGC sp->cw2);
  564. X    }
  565. X    XClearWindow(DARGC sp->w1);
  566. X    XClearWindow(DARGC sp->w2);
  567. X    XRaiseWindow(DARGC sp->w1);
  568. X    if (cp->o.altwin) XRaiseWindow(DARGC sp->w2);
  569. X    XSelectInput(DARGC sp->w1,InputMask(cp));
  570. X    if (cp->o.altwin) XSelectInput(DARGC sp->w2,InputMask(cp));
  571. X#   ifdef X11
  572. X    XSetBackground(sp->d,sp->gc1,cp->colorbg);
  573. X    XSetForeground(sp->d,sp->gc1,cp->colorfg);
  574. X    XSetFunction(sp->d,sp->gc1,cp->func);
  575. X    XSetFunction(sp->d,sp->gc2,cp->func);
  576. X    if (cp->o.stipple&&cp->o.tile) style = FillOpaqueStippled;
  577. X    else if (cp->o.stipple) style = FillStippled;
  578. X    else if (cp->o.tile) style = FillTiled;
  579. X    else style = FillSolid;
  580. X    XSetFillStyle(sp->d,sp->gc1,style);
  581. X    XSetFillStyle(sp->d,sp->gc2,style);
  582. X    if (cp->o.stipple) style = LineOnOffDash;
  583. X    else if (cp->o.tile) style = LineDoubleDash;
  584. X    else style = LineSolid;
  585. X    XSetLineAttributes(sp->d,sp->gc1,cp->p.lwidth,style,CapButt,JoinMiter);
  586. X    XSetLineAttributes(sp->d,sp->gc2,cp->p.lwidth,style,CapButt,JoinMiter);
  587. X#   endif X11
  588. X    XSync(DARGC 1);
  589. X    if (cp->o.profile) ProfControl(1);
  590. X}
  591. X
  592. Xvoid StartIteration(sp,cp)
  593. X    State*  sp;
  594. X    Cmd*    cp;
  595. X{
  596. X    Pixel colortemp;
  597. X
  598. X    if (!cp->o.drag) {
  599. X    cp->shift += cp->dx;
  600. X    if ((cp->shift<0)||(cp->shift>cp->p.maxshift)) {
  601. X        cp->dx = -cp->dx;
  602. X        cp->dy = -cp->dy;
  603. X        cp->shift += 2*cp->dx;
  604. X    }
  605. X    cp->x += cp->dx;
  606. X    cp->y += cp->dy;
  607. X    }
  608. X    if (cp->o.altcolor) {
  609. X    colortemp = cp->colorbg;
  610. X    cp->colorbg = cp->colorfg;
  611. X    cp->colorfg = colortemp;
  612. X#    ifdef X11
  613. X        XSetBackground(sp->d,sp->gc1,cp->colorbg);
  614. X        XSetForeground(sp->d,sp->gc1,cp->colorfg);
  615. X#    endif X11
  616. X    }
  617. X    if ((cp->o.altgc)&&(cp->gc==sp->gc1)) cp->gc = sp->gc2;
  618. X    else cp->gc = sp->gc1;
  619. X    if ((cp->o.altwin)&&(cp->w==sp->w1)) {
  620. X    cp->dest = sp->dest2;
  621. X    cp->src = sp->src2;
  622. X    cp->w = sp->w2;
  623. X    }
  624. X    else {
  625. X    cp->dest = sp->dest1;
  626. X    cp->src = sp->src1;
  627. X    cp->w = sp->w1;
  628. X    }
  629. X    if (cp->o.unbatched) XFlush(DARG);
  630. X}
  631. X
  632. Xvoid Erase(sp,cp)
  633. X    State*  sp;
  634. X    Cmd*    cp;
  635. X{
  636. X    int x = cp->x;
  637. X    int y = cp->y;
  638. X    int bbx = cp->bbx;
  639. X    int bby = cp->bby;
  640. X
  641. X    if (cp->bbx<0) {
  642. X    x += cp->bbx;
  643. X    bbx = -bbx;
  644. X    }
  645. X    if (cp->bby<0) {
  646. X    y += cp->bby;
  647. X    bby = -bby;
  648. X    }
  649. X#   ifdef X10
  650. X    XPixFill(cp->w,x,y,bbx,bby,_BlackPixel,0,GXcopy,AllPlanes);
  651. X#   else
  652. X    XFillRectangle(
  653. X        sp->d,cp->dest,DefaultGC(sp->d,DefaultScreen(sp->d)),x,y,bbx,bby
  654. X    );
  655. X#   endif
  656. X}
  657. X
  658. Xvoid Finish(sp,cp)
  659. X    State*  sp;
  660. X    Cmd*    cp;
  661. X{
  662. X    int        i;
  663. X
  664. X    if (cp->o.profile) ProfControl(0);
  665. X    if (cp->o.overlap) {
  666. X    XUnmapWindow(DARGC sp->cw1);
  667. X    if (cp->o.altwin) XUnmapWindow(DARGC sp->cw2);
  668. X    }
  669. X#   ifdef X11
  670. X    if (cp->o.offdest) {
  671. X        XCopyArea(
  672. X        sp->d,sp->offpix,sp->w1,sp->gc1,0,0,sp->winsize,sp->winsize,0,0
  673. X        );
  674. X    }
  675. X#   endif X11
  676. X    XSync(DARGC 0);
  677. X    fprintf(Out(sp,cp),"# ");
  678. X    if (cp->result!=Succeeded) {
  679. X    fprintf(Out(sp,cp),"result=%s",ResultMsgs[(int)cp->result]);
  680. X    }
  681. X    else {
  682. X    fprintf(
  683. X        Out(sp,cp),"hload=%.1f  time=%.3fmsec  rate=%.1f/sec",GetLoad(),
  684. X        cp->time*1000/cp->iterations,cp->iterations/cp->time
  685. X    );
  686. X    }
  687. X    if (strlen(cp->p.tag)) fprintf(Out(sp,cp),"  tag=%s  ",cp->p.tag);
  688. X    putc('\n',Out(sp,cp));
  689. X    putc('\n',stderr);
  690. X    fflush(Out(sp,cp));
  691. X    fflush(stderr);
  692. X    if (strcmp(sp->fonts,sp->defaults.fonts)) SetFonts(sp,&sp->defaults);
  693. X    if (strcmp(sp->outfile,sp->defaults.outfile)) SetOutfile(sp,&sp->defaults);
  694. X    if (sp->winsize!=sp->defaults.winsize) SetWinsize(sp,&sp->defaults);
  695. X}
  696. X
  697. Xvoid ExecDrag(sp,cp)
  698. X    State*  sp;
  699. X    Cmd*    cp;
  700. X{
  701. X    XEvent        e;
  702. X    int            i;
  703. X    XMotionEvent*   mep;
  704. X    double        t1;
  705. X    Window        qw;
  706. X
  707. X#   ifdef X10
  708. X    mep = (XMotionEvent*)&e;
  709. X#   else
  710. X    mep = &e.xmotion;
  711. X#   endif
  712. X    cp->iterations = 0;
  713. X    cp->o.altwin = false;
  714. X    XClearWindow(DARGC sp->w1);
  715. X    (*Ops[(int)cp->index][(int)StartOp])(sp,cp);
  716. X    Help(
  717. X    stderr,
  718. X    "    Drag test: move cursor in window while pressing a mouse button"
  719. X    );
  720. X    fflush(stderr);
  721. X    XDefineCursor(DARGC cp->w,sp->cursor);
  722. X    do XNextEvent(DARGC &e); while (e.type!=ButtonPress);
  723. X    t1 = GetTime(sp);
  724. X    while (e.type!=ButtonRelease) {
  725. X    XSync(DARGC false);
  726. X    if (cp->o.poll) {
  727. X        if (!XCheckMaskEvent(DARGC ButtonReleaseMask,&e)) {
  728. X        e.type = MotionNotify;
  729. X#        ifdef X10
  730. X            XQueryMouse(cp->w,&mep->x,&mep->y,&qw);
  731. X#        else
  732. X            XQueryPointer(
  733. X            sp->d,cp->w,&qw,&qw,&i,&i,&mep->x,&mep->y,&i
  734. X            );
  735. X#        endif
  736. X        }
  737. X    }
  738. X    else do {
  739. X        XNextEvent(DARGC &e);
  740. X    } while (QLength(DARG) && (e.type==MotionNotify));
  741. X    (*Ops[(int)cp->index][(int)EraseOp])(sp,cp);
  742. X    cp->dx = mep->x-cp->x;
  743. X    cp->dy = mep->y-cp->y;
  744. X    cp->x = mep->x;
  745. X    cp->y = mep->y;
  746. X    (*Ops[(int)cp->index][(int)DoOp])(sp,cp);
  747. X    cp->iterations++;
  748. X    }
  749. X    cp->time = GetTime(sp)-t1;
  750. X    XUndefineCursor(DARGC cp->w);
  751. X    (*Ops[(int)cp->index][(int)FinishOp])(sp,cp);
  752. X    XFlush(DARG);
  753. X}
  754. X
  755. Xvoid ExecOp(sp,cp)
  756. X    State*  sp;
  757. X    Cmd*    cp;
  758. X{
  759. X    
  760. X    bool    done;
  761. X    int        i;
  762. X    double  t1;
  763. X
  764. X    (*Ops[(int)cp->index][(int)StartOp])(sp,cp);
  765. X    cp->iterations = 1;
  766. X    done = (bool)(cp->result!=Succeeded);
  767. X    while (!done) {
  768. X    t1 = GetTime(sp);
  769. X    for (i=0;i<cp->iterations;i++) {
  770. X        (*Ops[(int)cp->index][(int)DoOp])(sp,cp);
  771. X    }
  772. X    cp->time = GetTime(sp)-t1;
  773. X    if (((int)cp->time)>=cp->p.timegoal) done = true;
  774. X    else {
  775. X        cp->iterations =
  776. X        (int)(cp->iterations*cp->p.timegoal/(cp->time+.0001))+1;
  777. X    }
  778. X    }
  779. X    (*Ops[(int)cp->index][(int)FinishOp])(sp,cp);
  780. X}
  781. X
  782. Xvoid ExecCmds(sp)
  783. X    State* sp;
  784. X{
  785. X    Cmd    c;
  786. X
  787. X    while (GetCmd(sp,&c)) {
  788. X    if (c.o.drag) ExecDrag(sp,&c);
  789. X    else ExecOp(sp,&c);
  790. X    }
  791. X}
  792. END_OF_FILE
  793. if test 6770 -ne `wc -c <'exec.c'`; then
  794.     echo shar: \"'exec.c'\" unpacked with wrong size!
  795. fi
  796. # end of 'exec.c'
  797. fi
  798. if test -f 'gbench.h' -a "${1}" != "-c" ; then 
  799.   echo shar: Will not clobber existing file \"'gbench.h'\"
  800. else
  801. echo shar: Extracting \"'gbench.h'\" \(5690 characters\)
  802. sed "s/^X//" >'gbench.h' <<'END_OF_FILE'
  803. X#include <ctype.h>
  804. X#include <nlist.h>
  805. X#include <math.h>
  806. X#include <stdio.h>
  807. X#include <string.h>
  808. X#include <sys/time.h>
  809. X
  810. X#ifdef SUN3
  811. X#define FIXLOAD
  812. X#endif
  813. X#ifdef SUN4
  814. X#define FIXLOAD
  815. X#endif
  816. X
  817. X#ifdef X10
  818. X#   include <X10/Xlib.h>
  819. X#   define _BlackPixel        BlackPixel
  820. X#   define ButtonPress        ButtonPressed
  821. X#   define ButtonPressMask    ButtonPressed
  822. X#   define ButtonRelease    ButtonReleased
  823. X#   define ButtonReleaseMask    ButtonReleased
  824. X#   define DARG
  825. X#   define DARGC
  826. X#   define DefaultFonts        "4x6,6x10,6x13,9x15,ice34"
  827. X#   define _DisplayHeight    DisplayHeight()
  828. X#   define _DisplayWidth    DisplayWidth()
  829. X#   define Drawable        Window
  830. X#   define ExposeRegionMask    ExposeRegion
  831. X#   define ExposureMask        ExposeCopy
  832. X#   define GC            int
  833. X#   define MotionNotify        MouseMoved
  834. X#   define PointerMotionMask    MouseMoved
  835. X#   define _RootWindow        RootWindow
  836. X#   define _WhitePixel        WhitePixel
  837. X#   define XClearWindow        XClear
  838. X#   define XCreateSimpleWindow    XCreateWindow
  839. X#   define XFontStruct        FontInfo
  840. X#   define XFreeFont        XCloseFont
  841. X#   define XGraphicsExposeEvent    XExposeEvent
  842. X#   define XPoint        Vertex
  843. X#   define XTextItem        char
  844. X#   define XMotionEvent        XMouseMovedEvent
  845. X#else
  846. X#   include <X11/Xlib.h>
  847. X#   include <X11/X.h>
  848. X#   include <X11/Xutil.h>
  849. X#   include <X11/cursorfont.h>
  850. X#   define _BlackPixel        BlackPixel(sp->d,DefaultScreen(sp->d))
  851. X#   define BlackPixmap        _BlackPixel
  852. X#   define DARG            sp->d
  853. X#   define DARGC        DARG,
  854. X#   define DefaultFonts        "vg-??"
  855. X#   define _DisplayHeight    DisplayHeight(sp->d,DefaultScreen(sp->d))
  856. X#   define _DisplayWidth    DisplayWidth(sp->d,DefaultScreen(sp->d))
  857. X#   define ExposeRegionMask    0
  858. X#   define Pattern        int
  859. X#   define _RootWindow        DefaultRootWindow(sp->d)
  860. X#   define _WhitePixel        WhitePixel(sp->d,DefaultScreen(sp->d))
  861. X#   define WhitePixmap        _WhitePixel
  862. X#endif
  863. X
  864. X#define Border        10
  865. X#define DefaultAngle    350
  866. X#define DefaultAspect    1.
  867. X#define DefaultLwidth   1
  868. X#define DefaultMaxshift    32
  869. X#define DefaultNchar    10
  870. X#define DefaultNvert    4
  871. X#define DefaultNwin    10
  872. X#define DefaultOffset    .5
  873. X#define DefaultPtsize    12
  874. X#define DefaultSize    100
  875. X#define DefaultTimegoal    1
  876. X#define DefaultWinsize  _DisplayWidth/2
  877. X#define MaxIndepth    10
  878. X#define MaxNum        1000000
  879. X#define MaxPositional    5
  880. X#define MaxStr        120
  881. X#define MaxVert        31
  882. X#define MaxFonts    16
  883. X#define MinAspect    .1
  884. X#define nil        0
  885. X#define NumOps        9
  886. X#define OverlapSize    2
  887. X#define Pi        3.141592654
  888. X#define PolyAngle    Pi/18
  889. X#define Version         1.0
  890. X
  891. X#define Sign(x) ((x)>=0?1:-1)
  892. X
  893. Xtypedef enum {false,true} bool;
  894. X
  895. Xtypedef double Load;
  896. X
  897. Xtypedef void (*Op)();
  898. X
  899. Xtypedef enum {
  900. X    NilIndex = -1,
  901. X    ArcIndex,
  902. X    BlitIndex,
  903. X    MapIndex,
  904. X    NopIndex,
  905. X    PointIndex,
  906. X    PolyIndex,
  907. X    RectIndex,
  908. X    TextIndex,
  909. X    VecIndex
  910. X} OpIndex;
  911. X
  912. Xtypedef enum {StartOp,DoOp,EraseOp,FinishOp} OpType;
  913. X
  914. Xtypedef struct {
  915. X    bool    altcolor;
  916. X    bool    altfont;
  917. X    bool    altgc;
  918. X    bool    altwin;
  919. X    bool    drag;
  920. X    bool    fill;
  921. X    bool    invert;
  922. X    bool    offdest;
  923. X    bool    offsrc;
  924. X    bool    overlap;
  925. X    bool    poll;
  926. X    bool    polyself;
  927. X    bool    polywind;
  928. X    bool    profile;
  929. X    bool    setdefaults;
  930. X    bool    silent;
  931. X    bool    stipple;
  932. X    bool    tile;
  933. X    bool    unbatched;
  934. X} OptFlags;
  935. X
  936. Xtypedef struct {
  937. X    int        angle;
  938. X    float   aspect;
  939. X    int        count;
  940. X    char    fonts[MaxStr];
  941. X    int        ptsize;
  942. X    int        lwidth;
  943. X    int        maxshift;
  944. X    float   offset;
  945. X    int        nchar;
  946. X    int        nwin;
  947. X    int        nvert;
  948. X    char    opts[MaxStr];
  949. X    char    outfile[MaxStr];
  950. X    int        size;
  951. X    char    tag[MaxStr];
  952. X    int        timegoal;
  953. X    int        winsize;
  954. X} Params;
  955. X
  956. Xtypedef unsigned long Pixel;
  957. X
  958. Xtypedef enum {
  959. X    Succeeded,
  960. X    CmdNotSupported,
  961. X    OptNotSupported,
  962. X    NoFonts,
  963. X    NoOffscreenMem
  964. X} Result;
  965. X
  966. Xtypedef double Rtime;
  967. X
  968. Xtypedef struct {
  969. X    char*   cur;
  970. X    char*   end;
  971. X} TokenState;
  972. X
  973. Xtypedef struct {
  974. X    int        bbx;
  975. X    int        bby;
  976. X    Pixel    colorbg;
  977. X    Pixel    colorfg;
  978. X    Drawable    dest;
  979. X    int        dx;
  980. X    int        dy;
  981. X    Font    fontid;
  982. X    int        func;
  983. X    GC        gc;
  984. X    OpIndex    index;
  985. X    int        iterations;
  986. X    OptFlags    o;
  987. X    Params    p;
  988. X    Result    result;
  989. X    int        shift;
  990. X    int        size[3];
  991. X    Drawable    src;
  992. X    double    time;
  993. X    Window    w;
  994. X    int        x;
  995. X    int        y;
  996. X} Cmd;
  997. X
  998. Xtypedef struct {
  999. X    bool        altwin;
  1000. X    int            argc;
  1001. X    int            argindex;
  1002. X    char**        argv;
  1003. X    Cursor        cursor;
  1004. X    Window        cw1;
  1005. X    Window        cw2;
  1006. X    Display*        d;
  1007. X    Params        defaults;
  1008. X    Drawable        dest1;
  1009. X    Drawable        dest2;
  1010. X    char        disphost[MaxStr];
  1011. X    char        fonts[MaxStr];
  1012. X    XFontStruct*    fontinfo[MaxFonts];
  1013. X    GC            gc1;
  1014. X    GC            gc2;
  1015. X    char*        gxname;
  1016. X    char        host[MaxStr];
  1017. X    int            indepth;
  1018. X    FILE*        infds[MaxIndepth+1];
  1019. X    char        instr[MaxStr+1];
  1020. X    Drawable        offpix;
  1021. X    FILE*        outfd;
  1022. X    char        outfile[MaxStr+1];
  1023. X    char        outstr[MaxStr+1];
  1024. X    Pattern        pattern;
  1025. X    OpIndex        previndex;
  1026. X    Params        prevparams;
  1027. X    int            scriptindex;
  1028. X    Drawable        src1;
  1029. X    Drawable        src2;
  1030. X    bool        strinput;
  1031. X    bool        supcmds[NumOps];
  1032. X    OptFlags        supopts;
  1033. X    XTextItem        texts[MaxStr];
  1034. X    Pixmap        tile;
  1035. X    TokenState        ts;
  1036. X    XPoint        v[MaxVert+1];
  1037. X    Window        w1;
  1038. X    Window        w2;
  1039. X    int            winsize;
  1040. X} State;
  1041. X
  1042. Xbool    GetCmd();
  1043. XLoad    GetLoad();
  1044. XOpIndex    GetOpIndex();
  1045. XRtime    GetTime();
  1046. XFILE*    Out();
  1047. Xvoid    Start(),Erase(),Finish();
  1048. Xvoid    StartArc(),DoArc();
  1049. Xvoid    StartBlit(),DoBlit();
  1050. Xvoid    StartMap(),DoMap(),FinishMap();
  1051. Xvoid    DoNop();
  1052. Xvoid    StartPoint(),DoPoint();
  1053. Xvoid    StartPoly(),DoPoly();
  1054. Xvoid    StartRect(),DoRect();
  1055. Xvoid    StartText(),DoText();
  1056. Xvoid    StartVec(),DoVec();
  1057. Xchar*    StrToken();
  1058. X
  1059. Xextern char*    OpNames[NumOps][1+MaxPositional];
  1060. Xextern Op    Ops[NumOps][4];
  1061. Xextern char*    ResultMsgs[];
  1062. Xextern char*    Script[];
  1063. END_OF_FILE
  1064. if test 5690 -ne `wc -c <'gbench.h'`; then
  1065.     echo shar: \"'gbench.h'\" unpacked with wrong size!
  1066. fi
  1067. # end of 'gbench.h'
  1068. fi
  1069. if test -f 'main.c' -a "${1}" != "-c" ; then 
  1070.   echo shar: Will not clobber existing file \"'main.c'\"
  1071. else
  1072. echo shar: Extracting \"'main.c'\" \(8226 characters\)
  1073. sed "s/^X//" >'main.c' <<'END_OF_FILE'
  1074. X#include <gbench.h>
  1075. X
  1076. X#ifdef X10
  1077. X#   include <X10/bitmaps/gray1.bitmap>
  1078. X#   include <X10/cursors/target.cursor>
  1079. X#   include <X10/cursors/target_mask.cursor>
  1080. X#else
  1081. X#   include <X11/bitmaps/dot>
  1082. X#   include <X11/bitmaps/gray1>
  1083. X#endif
  1084. X
  1085. Xchar* OpNames[NumOps][1+MaxPositional] = {
  1086. X    {"arc",    "opts",    "size",    "aspect",   "angle",    "lwidth"},
  1087. X    {"blit",    "opts",    "size", "offset",   nil,    nil},
  1088. X    {"map",    "opts",    "size", "nwin",        nil,    nil},
  1089. X    {"nop",     "opts",    nil,    nil,        nil,    nil},
  1090. X    {"point",    "opts",    nil,    nil,        nil,    nil},
  1091. X    {"poly",    "opts",    "size",    "nvert",    "lwidth",   nil},
  1092. X    {"rect",    "opts",    "size",    "lwidth",    nil,    nil},
  1093. X    {"text",    "opts",    "nchar","ptsize",   nil,    nil},
  1094. X    {"vec",    "opts",    "size",    "angle",    "lwidth",   nil}
  1095. X};
  1096. X
  1097. XOp Ops[NumOps][4] = {
  1098. X    {StartArc,    DoArc,    Erase,  Finish},
  1099. X    {StartBlit,    DoBlit,    Erase,  Finish},
  1100. X    {StartMap,    DoMap,    Erase,  FinishMap},
  1101. X    {Start,    DoNop,    Erase,  Finish},
  1102. X    {StartPoint,DoPoint,Erase,    Finish},
  1103. X    {StartPoly,    DoPoly,    Erase,  Finish},
  1104. X    {StartRect, DoRect,    Erase,  Finish},
  1105. X    {StartText, DoText,    Erase,  Finish},
  1106. X    {StartVec,    DoVec,    Erase,  Finish}
  1107. X};
  1108. X
  1109. Xchar* ResultMsgs[] = {
  1110. X    "Succeeded",
  1111. X    "CmdNotSupported",
  1112. X    "OptNotSupported",
  1113. X    "NoFonts",
  1114. X    "NoOffscreenMem"
  1115. X};
  1116. X
  1117. Xchar* Script[] = {
  1118. X    "@# Starting script",
  1119. X    "c",
  1120. X    "a",
  1121. X    "a f 10",
  1122. X    "a f 100",
  1123. X    "b",
  1124. X    "n",
  1125. X    "point",
  1126. X    "poly",
  1127. X    "poly f 10",
  1128. X    "poly f 100",
  1129. X    "r",
  1130. X    "r f 10",
  1131. X    "r f 100",
  1132. X    "t n 1",
  1133. X    "t n 10",
  1134. X    "v n 10",
  1135. X    "v n 100",
  1136. X    "@# End of script",
  1137. X    nil
  1138. X};
  1139. X
  1140. Xstatic char* pname = "gbench";
  1141. X
  1142. Xvoid SetFonts(sp,pp)
  1143. X    State*  sp;
  1144. X    Params* pp;
  1145. X{
  1146. X    int        findex = 0;
  1147. X    int        foundcount;
  1148. X    char**    foundlist;
  1149. X    int        i;
  1150. X    char*    name;
  1151. X    char*    np = pp->fonts;
  1152. X    char    nlist[MaxStr];
  1153. X    TokenState    ts;
  1154. X
  1155. X    strcpy(nlist,pp->fonts);
  1156. X    for (i=0;(i<MaxFonts)&&sp->fontinfo[i];i++) {
  1157. X    XFreeFont(DARGC sp->fontinfo[i]);
  1158. X    sp->fontinfo[i] = nil;
  1159. X    }
  1160. X    if (name=StrToken(nlist,",",&ts)) do {
  1161. X#    ifdef X10
  1162. X        if (sp->fontinfo[findex]=XOpenFont(name)) {
  1163. X        sp->fontinfo[findex]->width = XQueryWidth("AA",
  1164. X            sp->fontinfo[findex]->id)/2+1;
  1165. X        sprintf(np,"%s,",name);
  1166. X        np += strlen(np);
  1167. X        findex++;
  1168. X        }
  1169. X#    else
  1170. X        foundlist = XListFonts(sp->d,name,MaxFonts,&foundcount);
  1171. X        for (i=0;(i<foundcount)&&(findex<MaxFonts);i++)
  1172. X        if (sp->fontinfo[findex]=XLoadQueryFont(sp->d,foundlist[i])) {
  1173. X            sprintf(np,"%s,",foundlist[i]);
  1174. X            np += strlen(np);
  1175. X            findex++;
  1176. X        }
  1177. X        XFreeFontNames(foundlist);
  1178. X#    endif
  1179. X    } while ((findex<MaxFonts)&&(name=StrToken(nil,",",&ts)));
  1180. X    if (np>pp->fonts) *--np = '\0';
  1181. X    strcpy(sp->fonts,pp->fonts);
  1182. X}
  1183. X
  1184. Xvoid SetOutfile(sp,pp)
  1185. X    State*  sp;
  1186. X    Params* pp;
  1187. X{
  1188. X    if (sp->outfd!=stdout) fclose(sp->outfd);
  1189. X    if (!strcmp(pp->outfile,"stdout")) sp->outfd = stdout;
  1190. X    else if (!(sp->outfd=fopen(pp->outfile,"a"))) {
  1191. X    sp->outfd = stdout;
  1192. X    strcpy(pp->outfile,"stdout");
  1193. X    }
  1194. X    strcpy(sp->outfile,pp->outfile);
  1195. X}
  1196. X
  1197. Xvoid SetWinsize(sp,pp)
  1198. X    State*  sp;
  1199. X    Params* pp;
  1200. X{
  1201. X#   ifdef X11
  1202. X    XSizeHints sh;
  1203. X#   endif X11
  1204. X
  1205. X#   ifdef X10
  1206. X    XChangeWindow(sp->w1,pp->winsize,pp->winsize);
  1207. X    XChangeWindow(sp->w2,pp->winsize,pp->winsize);
  1208. X#   else
  1209. X    sh.flags = USSize|PAspect;
  1210. X    sh.width = sh.height = pp->winsize;
  1211. X    sh.min_aspect.x = sh.max_aspect.x = sh.width;
  1212. X    sh.min_aspect.y = sh.max_aspect.y = sh.height;
  1213. X    XResizeWindow(sp->d,sp->w1,pp->winsize,pp->winsize);
  1214. X    XSetNormalHints(sp->d,sp->w1,&sh);
  1215. X    XResizeWindow(sp->d,sp->w2,pp->winsize,pp->winsize);
  1216. X    XSetNormalHints(sp->d,sp->w2,&sh);
  1217. X    if (pp->winsize>sp->winsize||!sp->offpix) {
  1218. X        if (sp->offpix) XFreePixmap(sp->d,sp->offpix);
  1219. X        sp->offpix = XCreatePixmap(
  1220. X        sp->d,_RootWindow,pp->winsize,pp->winsize,
  1221. X        DefaultDepth(sp->d,DefaultScreen(sp->d))
  1222. X        );
  1223. X    }
  1224. X#   endif
  1225. X    sp->winsize = pp->winsize;
  1226. X    XFlush(DARG);
  1227. X}
  1228. X
  1229. Xvoid InitParams(sp,pp)
  1230. X    State*  sp;
  1231. X    Params* pp;
  1232. X{
  1233. X    pp->angle = DefaultAngle;
  1234. X    pp->aspect = DefaultAspect;
  1235. X    pp->count = 1;
  1236. X    strcpy(pp->fonts,DefaultFonts);
  1237. X    pp->ptsize = DefaultPtsize;
  1238. X    pp->lwidth = DefaultLwidth;
  1239. X    pp->maxshift = DefaultMaxshift;
  1240. X    pp->offset = DefaultOffset;
  1241. X    pp->nchar = DefaultNchar;
  1242. X    pp->nwin = DefaultNwin;
  1243. X    pp->nvert = DefaultNvert;
  1244. X    *pp->opts = '\0';
  1245. X    strcpy(pp->outfile,"stdout");
  1246. X    pp->size = DefaultSize;
  1247. X    *pp->tag = '\0';
  1248. X    pp->timegoal = DefaultTimegoal;
  1249. X    pp->winsize = DefaultWinsize;
  1250. X    if (strcmp(sp->fonts,pp->fonts)) SetFonts(sp,pp);
  1251. X    if (strcmp(sp->outfile,pp->outfile)) SetOutfile(sp,pp);
  1252. X    if (sp->winsize!=pp->winsize) SetWinsize(sp,pp);
  1253. X}
  1254. X
  1255. Xvoid InitState(sp)
  1256. X    State* sp;
  1257. X{
  1258. X    char*   cp;
  1259. X    int        i;
  1260. X    int        j;
  1261. X#   ifdef X11
  1262. X    XGCValues   gcv;
  1263. X    XSizeHints  sh;
  1264. X#   endif X11
  1265. X
  1266. X    sp->altwin = false;
  1267. X    sp->argindex = 1;
  1268. X    *sp->fonts = '\0';
  1269. X    for (i=0;i<MaxFonts;i++) sp->fontinfo[i] = nil;
  1270. X    sp->infds[0] = stdin;
  1271. X    sp->indepth = 0;
  1272. X    sp->offpix = nil;
  1273. X    sp->outfd = stdout;
  1274. X    strcpy(sp->outfile,"stdout");
  1275. X    sp->winsize = DefaultWinsize;
  1276. X    InitParams(sp,&sp->defaults);
  1277. X    sp->previndex = NilIndex;
  1278. X    InitParams(sp,&sp->prevparams);
  1279. X    gethostname(sp->host,MaxStr);
  1280. X    strncpy(sp->disphost,getenv("DISPLAY"),MaxStr);
  1281. X    if (cp=strchr(sp->disphost,':')) *cp = '\0';
  1282. X    if (!strcmp(sp->disphost,"unix")) strcpy(sp->disphost,sp->host);
  1283. X    for (i=0;i<MaxStr;i++) sp->outstr[i] = 'A'+(i%26);
  1284. X    sp->scriptindex = -1;
  1285. X    sp->w1 = XCreateSimpleWindow(
  1286. X    DARGC _RootWindow,0,0,sp->winsize,sp->winsize,2,WhitePixmap,BlackPixmap
  1287. X    );
  1288. X    sp->cw1 = XCreateSimpleWindow(
  1289. X    DARGC sp->w1,0,0,OverlapSize,OverlapSize,1,WhitePixmap,BlackPixmap
  1290. X    );
  1291. X    sp->w2 = XCreateSimpleWindow(
  1292. X    DARGC _RootWindow,sp->winsize,0,sp->winsize,sp->winsize,2,WhitePixmap,
  1293. X    BlackPixmap
  1294. X    );
  1295. X    sp->cw2 = XCreateSimpleWindow(
  1296. X    DARGC sp->w2,0,0,OverlapSize,OverlapSize,1,WhitePixmap,BlackPixmap
  1297. X    );
  1298. X    sp->dest1 = sp->w1;
  1299. X    sp->src1 = sp->w1;
  1300. X    sp->dest2 = sp->w2;
  1301. X    sp->src2 = sp->w2;
  1302. X    for (i=0;i<NumOps;i++) sp->supcmds[i] = true;
  1303. X    for (i=0;i<(sizeof(OptFlags)/sizeof(bool));i++) {
  1304. X    ((bool*)&sp->supopts)[i] = true;
  1305. X    }
  1306. X#   ifdef X10
  1307. X    sp->supcmds[(int)ArcIndex] = false;
  1308. X    sp->supcmds[(int)NopIndex] = false;
  1309. X    sp->supcmds[(int)PointIndex] = false;
  1310. X    sp->supopts.altfont = false;
  1311. X    sp->supopts.altgc = false;
  1312. X    sp->supopts.offdest = false;
  1313. X    sp->supopts.offsrc =false;
  1314. X    sp->supopts.polywind = false;
  1315. X    sp->cursor = XCreateCursor(
  1316. X        target_width,target_height,target_bits,target_mask_bits,
  1317. X        target_x_hot,target_y_hot,_WhitePixel,_BlackPixel,GXcopy
  1318. X    );
  1319. X    sp->gxname = "X10";
  1320. X    sp->offpix = sp->w1;
  1321. X    sp->pattern = XMakePattern(1,2,4);
  1322. X    sp->tile = XMakePixmap(
  1323. X        XStoreBitmap(gray1_width,gray1_height,gray1_bits),_WhitePixel,
  1324. X        _BlackPixel
  1325. X    );
  1326. X#   else
  1327. X    sp->cursor = XCreateFontCursor(sp->d,XC_target);
  1328. X    gcv.foreground = _WhitePixel;
  1329. X    gcv.background = _BlackPixel;
  1330. X    gcv.tile = XCreatePixmapFromBitmapData(
  1331. X        sp->d,_RootWindow,gray1_bits,gray1_width,gray1_height,_WhitePixel,
  1332. X        _BlackPixel,DefaultDepth(sp->d,DefaultScreen(sp->d))
  1333. X    );
  1334. X    gcv.stipple = XCreateBitmapFromData(
  1335. X        sp->d,_RootWindow,dot_bits,dot_width,dot_height
  1336. X    );
  1337. X    sp->gc1 = XCreateGC(
  1338. X        sp->d,_RootWindow,GCForeground|GCBackground|GCTile|GCStipple,&gcv
  1339. X    );
  1340. X    sp->gc2 = XCreateGC(
  1341. X        sp->d,_RootWindow,GCForeground|GCBackground|GCTile|GCStipple,&gcv
  1342. X    );
  1343. X    sp->gxname = "X11";
  1344. X    sh.flags = USPosition|USSize|PAspect;
  1345. X    sh.x = sh.y = 0;
  1346. X    sh.width = sh.height = sp->winsize;
  1347. X    sh.min_aspect.x = sh.max_aspect.x = sh.width;
  1348. X    sh.min_aspect.y = sh.max_aspect.y = sh.height;
  1349. X    XSetStandardProperties(
  1350. X        sp->d,sp->w1,"gbench w1","gbench w1",None,sp->argv,sp->argc,&sh
  1351. X    );
  1352. X    sh.x = sp->winsize;
  1353. X    XSetStandardProperties(
  1354. X        sp->d,sp->w2,"gbench w2","gbench w2",None,sp->argv,sp->argc,&sh
  1355. X    );
  1356. X    for (i=0;i<MaxStr;i++) {
  1357. X        sp->texts[i].chars = sp->outstr+i;
  1358. X        sp->texts[i].nchars = 1;
  1359. X        sp->texts[i].delta = 0;
  1360. X    }
  1361. X#   endif
  1362. X    MapWin(sp,sp->w1);
  1363. X    XClearWindow(DARGC sp->w1);
  1364. X    XFlush(DARG);
  1365. X}
  1366. X
  1367. Xint main(argc,argv)
  1368. X    int        argc;
  1369. X    char*   argv[];
  1370. X{
  1371. X    State   s;
  1372. X    State*  sp = &s;
  1373. X
  1374. X    s.argc = argc;
  1375. X    s.argv = argv;
  1376. X    ProfControl(0);
  1377. X    if (!(s.d=XOpenDisplay(0))) Fatal(pname,"Couldn't open display");
  1378. X    InitState(&s);
  1379. X    ExecCmds(&s);
  1380. X    XFlush(DARG);
  1381. X    return 0;
  1382. X}
  1383. END_OF_FILE
  1384. if test 8226 -ne `wc -c <'main.c'`; then
  1385.     echo shar: \"'main.c'\" unpacked with wrong size!
  1386. fi
  1387. # end of 'main.c'
  1388. fi
  1389. if test -f 'utils.c' -a "${1}" != "-c" ; then 
  1390.   echo shar: Will not clobber existing file \"'utils.c'\"
  1391. else
  1392. echo shar: Extracting \"'utils.c'\" \(8321 characters\)
  1393. sed "s/^X//" >'utils.c' <<'END_OF_FILE'
  1394. X#include <gbench.h>
  1395. X
  1396. Xint Abs(n)
  1397. X    int n;
  1398. X{
  1399. X    return n>=0?n:-n;
  1400. X}
  1401. X
  1402. Xvoid CopyParams(dp,sp)
  1403. X    Params* dp;
  1404. X    Params* sp;
  1405. X
  1406. X{
  1407. X    bcopy(sp,dp,sizeof(Params));
  1408. X}
  1409. X
  1410. Xvoid Fatal(p,e)
  1411. X    char*   p;
  1412. X    char*   e;
  1413. X{
  1414. X    fprintf(stderr,"%s:  ",p);
  1415. X    fprintf(stderr,e,p);
  1416. X    putc('\n',stderr);
  1417. X    exit(1);
  1418. X}
  1419. X
  1420. Xint FontIndex(sp,sizep)
  1421. X    State*  sp;
  1422. X    int*    sizep;
  1423. X{
  1424. X    int i;
  1425. X    int    mindist = _DisplayHeight;
  1426. X    int minindex = -1;
  1427. X    int minsize = *sizep;
  1428. X    int newsize;
  1429. X
  1430. X    for (i=0;(i<MaxFonts)&&sp->fontinfo[i];i++) {
  1431. X#    ifdef X10
  1432. X        newsize = sp->fontinfo[i]->height;
  1433. X#    else
  1434. X        newsize = sp->fontinfo[i]->ascent;
  1435. X#    endif
  1436. X    if (Abs(*sizep-newsize)<mindist) {
  1437. X        mindist = Abs(*sizep-newsize);
  1438. X        minindex = i;
  1439. X        minsize = newsize;
  1440. X    }
  1441. X    }
  1442. X    *sizep = minsize;
  1443. X    return minindex;
  1444. X}
  1445. X
  1446. XLoad GetLoad()
  1447. X{
  1448. X    int            kmem;
  1449. X    struct nlist    nl[2];
  1450. X#   ifdef FIXLOAD
  1451. X    long        load;
  1452. X#   else
  1453. X    double        load;
  1454. X#   endif
  1455. X
  1456. X    nl[0].n_name = "_avenrun";
  1457. X    nl[1].n_name = nil;
  1458. X    nlist("/vmunix",nl);
  1459. X    if (!nl[0].n_type) return 0.;
  1460. X    if ((kmem=open("/dev/kmem",0))<0) return 0.;
  1461. X    lseek(kmem,nl[0].n_value,0);
  1462. X    read(kmem,&load,sizeof(load));
  1463. X#   ifdef FIXLOAD
  1464. X    return load/256.;
  1465. X#   else
  1466. X    return load;
  1467. X#   endif
  1468. X}
  1469. X
  1470. XOpIndex GetOpIndex(opname)
  1471. X    char* opname;
  1472. X{
  1473. X    int i;
  1474. X    
  1475. X    for (i=0;i<NumOps;i++) {
  1476. X    if (!strncmp(opname,OpNames[i][0],strlen(opname))) return (OpIndex)i;
  1477. X    }
  1478. X    return NilIndex;
  1479. X}
  1480. X
  1481. XRtime GetTime(sp)
  1482. X    State*  sp;
  1483. X{
  1484. X    struct timeval t;
  1485. X
  1486. X    XSync(DARGC true);
  1487. X    gettimeofday(&t,0);
  1488. X    return t.tv_sec+t.tv_usec/1000000.;
  1489. X}
  1490. X
  1491. Xvoid Help(f,s)
  1492. X    FILE*   f;
  1493. X    char*   s;
  1494. X{
  1495. X    putc('#',f);
  1496. X    fputs(s,f);
  1497. X    putc('\n',f);
  1498. X}
  1499. X
  1500. Xint InputMask(cp)
  1501. X    Cmd* cp;
  1502. X{
  1503. X    int im = 0;
  1504. X    
  1505. X    if (cp->o.drag) im |= (ButtonPressMask|ButtonReleaseMask);
  1506. X    if (!cp->o.poll) im |= PointerMotionMask;
  1507. X    if (cp->o.overlap) im |= (ExposeRegionMask|ExposureMask);
  1508. X    return im;
  1509. X}
  1510. X
  1511. Xint Limit(n,min,max)
  1512. X    int    n;
  1513. X    int    min;
  1514. X    int    max;
  1515. X{
  1516. X    if (n<min) n = min;
  1517. X    else if (n>max) n = max;
  1518. X    return n;
  1519. X}
  1520. X
  1521. Xvoid MapWin(sp,w)
  1522. X    State*  sp;
  1523. X    Window  w;
  1524. X{
  1525. X#   ifdef X11
  1526. X        XEvent e;
  1527. X        XSelectInput(sp->d,w,StructureNotifyMask);
  1528. X#   endif X11
  1529. X    XMapWindow(DARGC w);
  1530. X#   ifdef X11
  1531. X        do
  1532. X            XNextEvent(sp->d,&e);
  1533. X        while (e.type!=MapNotify);
  1534. X#   endif X11
  1535. X}
  1536. X
  1537. Xvoid MoveClip(sp,cp,x,y)
  1538. X    State*  sp;
  1539. X    Cmd*    cp;
  1540. X    int        x;
  1541. X    int        y;
  1542. X{
  1543. X    if (cp->o.overlap) {
  1544. X    x += cp->p.maxshift/2-OverlapSize/2;
  1545. X    y += cp->p.maxshift/2-OverlapSize/2;
  1546. X    XMoveWindow(DARGC sp->cw1,x,y);
  1547. X    XMoveWindow(DARGC sp->cw2,x,y);
  1548. X    }
  1549. X}
  1550. X
  1551. Xvoid MoveVert(sp,cp,vcount)
  1552. X    State*  sp;
  1553. X    Cmd*    cp;
  1554. X    int        vcount;
  1555. X{
  1556. X    int i;
  1557. X    
  1558. X    if (cp->dx||cp->dy) for (i=0;i<=vcount;i++) {
  1559. X    sp->v[i].x += cp->dx;
  1560. X    sp->v[i].y += cp->dy;
  1561. X    }
  1562. X}
  1563. X
  1564. XFILE* Out(sp,cp)
  1565. X    State*  sp;
  1566. X    Cmd*    cp;
  1567. X{
  1568. X    if (cp->o.silent) return stderr;
  1569. X    else return sp->outfd;
  1570. X}
  1571. X
  1572. Xvoid PrintConfig(f,sp)
  1573. X    FILE*   f;
  1574. X    State*  sp;
  1575. X{
  1576. X    int t = time(0);
  1577. X
  1578. X    fprintf(f,"# host=%s\n",sp->host);
  1579. X    fprintf(f,"# display=%s\n",getenv("DISPLAY"));
  1580. X    fprintf(f,"# graphics=%s\n",sp->gxname);
  1581. X    fprintf(f,"# time=%s",ctime(&t));
  1582. X    fprintf(f,"# version=%.1f\n",Version);
  1583. X    fprintf(f,"# tag=%s\n",sp->defaults.tag);
  1584. X}
  1585. X
  1586. Xvoid PrintParam(f,pp,pre,name,post)
  1587. X    FILE*   f;
  1588. X    Params* pp;
  1589. X    char*   pre;
  1590. X    char*   name;
  1591. X    char*   post;
  1592. X{
  1593. X    fprintf(f,"%s",pre);
  1594. X    if (!strcmp(name,"angle")) fprintf(f,"%s=%d",name,pp->angle);
  1595. X    else if (!strcmp(name,"aspect")) fprintf(f,"%s=%.1f",name,pp->aspect);
  1596. X    else if (!strcmp(name,"count")) fprintf(f,"%s=%d",name,pp->count);
  1597. X    else if (!strcmp(name,"fonts")) fprintf(f,"%s=%s",name,pp->fonts);
  1598. X    else if (!strcmp(name,"ptsize")) fprintf(f,"%s=%d",name,pp->ptsize);
  1599. X    else if (!strcmp(name,"lwidth")) fprintf(f,"%s=%d",name,pp->lwidth);
  1600. X    else if (!strcmp(name,"maxshift")) fprintf(f,"%s=%d",name,pp->maxshift);
  1601. X    else if (!strcmp(name,"offset")) fprintf(f,"%s=%.1f",name,pp->offset);
  1602. X    else if (!strcmp(name,"nchar")) fprintf(f,"%s=%d",name,pp->nchar);
  1603. X    else if (!strcmp(name,"nwin")) fprintf(f,"%s=%d",name,pp->nwin);
  1604. X    else if (!strcmp(name,"nvert")) fprintf(f,"%s=%d",name,pp->nvert);
  1605. X    else if (!strcmp(name,"opts")) fprintf(f,"%s=%s",name,pp->opts);
  1606. X    else if (!strcmp(name,"outfile")) fprintf(f,"%s=%s",name,pp->outfile);
  1607. X    else if (!strcmp(name,"size")) fprintf(f,"%s=%d",name,pp->size);
  1608. X    else if (!strcmp(name,"tag")) fprintf(f,"%s=%s",name,pp->tag);
  1609. X    else if (!strcmp(name,"timegoal")) fprintf(f,"%s=%d",name,pp->timegoal);
  1610. X    else if (!strcmp(name,"winsize")) fprintf(f,"%s=%d",name,pp->winsize);
  1611. X    fprintf(f,"%s",post);
  1612. X}
  1613. X
  1614. Xvoid PrintParams(f,sp,pp)
  1615. X    FILE*   f;
  1616. X    State*  sp;
  1617. X    Params* pp;
  1618. X{
  1619. X    int i;
  1620. X
  1621. X    PrintParam(f,pp,"# ","angle","\n");
  1622. X    PrintParam(f,pp,"# ","aspect","\n");
  1623. X    PrintParam(f,pp,"# ","count","\n");
  1624. X    PrintParam(f,pp,"# ","fonts","\n");
  1625. X    PrintParam(f,pp,"# ","ptsize","\n");
  1626. X    PrintParam(f,pp,"# ","lwidth","\n");
  1627. X    PrintParam(f,pp,"# ","maxshift","\n");
  1628. X    PrintParam(f,pp,"# ","offset","\n");
  1629. X    PrintParam(f,pp,"# ","nchar","\n");
  1630. X    PrintParam(f,pp,"# ","nwin","\n");
  1631. X    PrintParam(f,pp,"# ","nvert","\n");
  1632. X    PrintParam(f,pp,"# ","opts","\n");
  1633. X    PrintParam(f,pp,"# ","outfile","\n");
  1634. X    PrintParam(f,pp,"# ","size","\n");
  1635. X    PrintParam(f,pp,"# ","tag","\n");
  1636. X    PrintParam(f,pp,"# ","timegoal","\n");
  1637. X    PrintParam(f,pp,"# ","winsize","\n");
  1638. X}
  1639. X
  1640. Xvoid PrintHelp(f)
  1641. X    FILE* f;
  1642. X{
  1643. X    int        i;
  1644. X    int        j;
  1645. X
  1646. X    Help(f,"Commands:");
  1647. X    for (i=0;i<NumOps;i++) {
  1648. X    fprintf(f,"#  %-8s",OpNames[i][0]);
  1649. X    for (j=0;(j<MaxPositional)&&OpNames[i][1+j];j++) {
  1650. X        fprintf(f," [%-6s]",OpNames[i][1+j]);
  1651. X    }
  1652. X    fprintf(f," [n=v]*\n");
  1653. X    }
  1654. X    Help(f,"  config");
  1655. X    Help(f,"  defaults [n=v]*");
  1656. X    Help(f,"  help");
  1657. X    Help(f,"  init");
  1658. X    Help(f,"  script   [filename]");
  1659. X    Help(f,"  quit");
  1660. X    Help(f,"  !");
  1661. X    Help(f,"  #");
  1662. X    Help(f,"Options:");
  1663. X    Help(f,"  ac    Alternate colors");
  1664. X    Help(f,"  af    Alternate fonts");
  1665. X    Help(f,"  ag    Alternate graphics contexts");
  1666. X    Help(f,"  aw    Alternate windows");
  1667. X    Help(f,"  d     Drag");
  1668. X    Help(f,"  f     Fill");
  1669. X    Help(f,"  i     Invert");
  1670. X    Help(f,"  m     Monitor for profiling");
  1671. X    Help(f,"  n     No options");
  1672. X    Help(f,"  o     Overlap");
  1673. X    Help(f,"  os    Offscreen source");
  1674. X    Help(f,"  od    Offscreen destination");
  1675. X    Help(f,"  p     Poll");
  1676. X    Help(f,"  ps    Polygon self-intersecting");
  1677. X    Help(f,"  pw    Polygon winding number fill");
  1678. X    Help(f,"  r     Reset defaults");
  1679. X    Help(f,"  s     Stipple");
  1680. X    Help(f,"  t     Tile");
  1681. X    Help(f,"  u     Unbatched");
  1682. X}
  1683. X
  1684. Xvoid ProfControl(i)
  1685. X    int i;
  1686. X{
  1687. X# ifdef GPROF
  1688. X    moncontrol(i);
  1689. X# endif GPROF
  1690. X}
  1691. X
  1692. Xchar* StrToken(s1,s2,tsp)
  1693. X    char*    s1;
  1694. X    char*    s2;
  1695. X    TokenState*    tsp;
  1696. X{
  1697. X    char* bp;
  1698. X
  1699. X    if (s1) {
  1700. X    tsp->cur = s1;
  1701. X    tsp->end = s1+strlen(s1);
  1702. X    }
  1703. X    else {
  1704. X    tsp->cur += strlen(tsp->cur)+1;
  1705. X    if (tsp->cur>=tsp->end) return nil;
  1706. X    }
  1707. X    tsp->cur += strspn(tsp->cur,s2);
  1708. X    if (bp=strpbrk(tsp->cur,s2)) *bp = '\0';
  1709. X    if (tsp->cur>=tsp->end) return nil;
  1710. X    else return tsp->cur;
  1711. X}
  1712. X
  1713. Xvoid UnmapWin(sp,w)
  1714. X    State*  sp;
  1715. X    Window  w;
  1716. X{
  1717. X#   ifdef X11
  1718. X        XEvent e;
  1719. X        XSelectInput(sp->d,w,StructureNotifyMask);
  1720. X#   endif X11
  1721. X    XUnmapWindow(DARGC w);
  1722. X#   ifdef X11
  1723. X        do
  1724. X            XNextEvent(sp->d,&e);
  1725. X        while (e.type!=UnmapNotify);
  1726. X#   endif X11
  1727. X}
  1728. X
  1729. X#ifdef X10
  1730. Xvoid X10Draw(sp,cp,vcount)
  1731. X    State*  sp;
  1732. X    Cmd*    cp;
  1733. X    int        vcount;
  1734. X{
  1735. X    if (cp->o.fill) {
  1736. X    if (cp->o.tile) {
  1737. X        XDrawTiled(cp->w,sp->v,vcount,sp->tile,cp->func,AllPlanes);
  1738. X    }
  1739. X    else XDrawFilled(cp->w,sp->v,vcount,cp->colorfg,cp->func,AllPlanes);
  1740. X    }
  1741. X    else {
  1742. X    if (cp->o.stipple) {
  1743. X        XDrawDashed(
  1744. X        cp->w,sp->v,vcount,cp->p.lwidth,cp->p.lwidth,cp->colorfg,
  1745. X        sp->pattern,cp->func,AllPlanes
  1746. X        );
  1747. X    }
  1748. X    else if (cp->o.tile) {
  1749. X        XDrawPatterned(
  1750. X        cp->w,sp->v,vcount,cp->p.lwidth,cp->p.lwidth,cp->colorfg,
  1751. X        cp->colorbg,sp->pattern,cp->func,AllPlanes
  1752. X        );
  1753. X    }
  1754. X    else if (vcount==2) {
  1755. X        XLine(
  1756. X        cp->w,sp->v[0].x,sp->v[0].y,sp->v[1].x,sp->v[1].y,cp->p.lwidth,
  1757. X        cp->p.lwidth,cp->colorfg,cp->func,AllPlanes
  1758. X        );
  1759. X    }
  1760. X    else {
  1761. X        XDraw(
  1762. X        cp->w,sp->v,vcount,cp->p.lwidth,cp->p.lwidth,cp->colorfg,
  1763. X        cp->func,AllPlanes
  1764. X        );
  1765. X    }
  1766. X    }
  1767. X}
  1768. X#endif X10
  1769. END_OF_FILE
  1770. if test 8321 -ne `wc -c <'utils.c'`; then
  1771.     echo shar: \"'utils.c'\" unpacked with wrong size!
  1772. fi
  1773. # end of 'utils.c'
  1774. fi
  1775. echo shar: End of archive 1 \(of 2\).
  1776. cp /dev/null ark1isdone
  1777. MISSING=""
  1778. for I in 1 2 ; do
  1779.     if test ! -f ark${I}isdone ; then
  1780.     MISSING="${MISSING} ${I}"
  1781.     fi
  1782. done
  1783. if test "${MISSING}" = "" ; then
  1784.     echo You have unpacked both archives.
  1785.     rm -f ark[1-9]isdone
  1786. else
  1787.     echo You still need to unpack the following archives:
  1788.     echo "        " ${MISSING}
  1789. fi
  1790. ##  End of shell archive.
  1791. exit 0
  1792.